package com.bnlr.lrparking.appui.order.adapter;

import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.bnlr.lrparking.R;
import com.bnlr.lrparking.appui.order.mode.OrderBean;
import com.bnlr.lrparking.widget.SuperTextView;

import java.util.List;

/**
 * Created by tian on 2017/11/21.
 */

public class OrderAdapter extends BaseQuickAdapter<OrderBean.DataBean,BaseViewHolder>{
    private OrderHandlerListener orderHandlerListener;
    public OrderAdapter(List<OrderBean.DataBean> data) {
        super(R.layout.item_order_layout,data);
    }
    public void setOrderHandlerListener(OrderHandlerListener orderHandlerListener) {
        this.orderHandlerListener = orderHandlerListener;
    }

    @Override
    protected void convert(final BaseViewHolder helper, final OrderBean.DataBean item) {
            helper.setText(R.id.tv_order_name, item.getName());
            helper.setText(R.id.tv_order_status, item.getStatus());
            ImageView ivPic = helper.getView(R.id.tv_order_pic);
            Glide.with(mContext).load(item.getPhotoUrl()).placeholder(R.mipmap.tab2_defaultgraph).error(R.mipmap.tab2_defaultgraph).into(ivPic);
            if (item.getSpaceOwerType() == 1) {
                helper.setText(R.id.stv_order_who, "开发商");
            } else {
                helper.setText(R.id.stv_order_who, "个人");
            }
            helper.setText(R.id.tv_order_title, item.getTitle());
            helper.setText(R.id.tv_order_number, item.getNumber());
            helper.setText(R.id.order_detail_address,item.getAddress());
             helper.setText(R.id.tv_order_price, item.getAdvanceMoneyStr());
            SuperTextView stages = helper.getView(R.id.stv_order_stages);
            SuperTextView pay = helper.getView(R.id.stv_order_call);
            SuperTextView delete = helper.getView(R.id.stv_order_delete);
            if (item.getIsByStage() == 0) {
                // 为分期
                stages.setText("申请分期");
            } else {
                // 已分期
                stages.setText("分期进度");
            }
            if (item.getStatusInt() == 2 || item.getStatusInt() == 3 || item.getStatusInt() == 5
                    || item.getStatusInt() == 6 || item.getStatusInt() == 7) {
                stages.setVisibility(View.GONE);
                pay.setVisibility(View.GONE);
                delete.setVisibility(View.VISIBLE);
            } else if (item.getStatusInt() == 1) {
                stages.setVisibility(View.VISIBLE);
                pay.setVisibility(View.GONE);
                delete.setVisibility(View.GONE);
                helper.setText(R.id.tv_order_tag,"实付：");
            }else if (item.getStatusInt() == 0) {
                stages.setVisibility(View.VISIBLE);
                pay.setVisibility(View.VISIBLE);
                delete.setVisibility(View.VISIBLE);
                helper.setText(R.id.tv_order_tag,"应付：");
            }
            delete.setOnTextViewClickListener(new SuperTextView.OnTextViewClickListener() {
                @Override
                public void onClick(View v) {
                    if (orderHandlerListener != null) {
                        orderHandlerListener.onDelete(v, helper.getAdapterPosition(), item);
                    }
                }
            });
            pay.setOnTextViewClickListener(new SuperTextView.OnTextViewClickListener() {
                @Override
                public void onClick(View v) {
                    if (orderHandlerListener != null) {
                        orderHandlerListener.onPay(v, item);
                    }
                }
            });
            stages.setOnTextViewClickListener(new SuperTextView.OnTextViewClickListener() {
                @Override
                public void onClick(View v) {
                    if (orderHandlerListener != null) {
                        orderHandlerListener.onStages(v, item);
                    }
                }
            });
    }
    public interface OrderHandlerListener {
        void onDelete (View view,int position,OrderBean.DataBean item);
        void onPay (View view,OrderBean.DataBean item);
        void onStages (View view,OrderBean.DataBean item);
    }
}


